package com.fzn3.day06;

import org.junit.Test;
import org.junit.jupiter.api.Assertions;

import java.util.Arrays;

/**
 * @author fzn
 * 描述：
 * @program DataStructure
 * @create 2023/3/13 13:02
 **/
public class TestArrayQueue3 {

    @Test
    public void offerLimit() {
        ArrayQueue3<Integer> queue = new ArrayQueue3<>(3);
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        Assertions.assertFalse(queue.offer(4));
        Assertions.assertFalse(queue.offer(5));
    }

    @Test
    public void offer() {
        ArrayQueue3<Integer> queue = new ArrayQueue3<>();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        queue.offer(4);
        queue.offer(5);

        Assertions.assertIterableEquals(Arrays.asList(1, 2, 3, 4, 5), queue);
    }

    @Test
    public void peek() {
        ArrayQueue3<Integer> queue = new ArrayQueue3<>();
        Assertions.assertNull(queue.peek());
        queue.offer(1);
        Assertions.assertEquals(1, queue.peek());
        queue.offer(2);
        Assertions.assertEquals(1, queue.peek());
    }

    @Test
    public void poll() {
        ArrayQueue3<Integer> queue = new ArrayQueue3<>();
        queue.offer(1);
        queue.offer(2);
        queue.offer(3);
        queue.offer(4);
        queue.offer(5);
        Assertions.assertEquals(1, queue.poll());
        Assertions.assertEquals(2, queue.poll());
        Assertions.assertEquals(3, queue.poll());
        Assertions.assertEquals(4, queue.poll());
        Assertions.assertEquals(5, queue.poll());
        Assertions.assertNull(queue.poll());
    }

}
